import { createRouter, createWebHistory } from 'vue-router'
import { menuItems } from './menu.js'
// 生成路由
function generateRoutesFromMenu(menuItems) {
  return menuItems.map(item => {
    const route = {
      path: item.path,
      name: item.routeName,
      component: item.component,
    };
    if (item.children && item.children.length > 0) {
      route.children = generateRoutesFromMenu(item.children);
    }
    return route;
  });
}

const routes = generateRoutesFromMenu(menuItems);
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

export default router
